﻿package org.abcFrame.core 
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.flash.UIMovieClip;
	
	import org.abcFrame.interfaces.IView;

	/**
	 * 所有可视化对象的基类，封装了可视化对象加载和卸载事件 
	 * onEnable接口中加载可视化对象的所有事件侦听
	 * offEnable接口中卸载可视化对象的所有事件侦听
	 * 通过调用onEnable和offEnable方法即可实现可视化对象的禁用和启用
	 * 
	 */	
	
	public class AbcView extends UIMovieClip implements IView
    {
		
		public function AbcView()
		{ 
			this.addEventListener(Event.ADDED_TO_STAGE, stageEvent)
		    this.addEventListener(Event.REMOVED_FROM_STAGE, stageEvent)
				
		}
		
		protected function stageEvent(e:Event):void
		{
			if (e.type == Event.ADDED_TO_STAGE)
			{
				onEnable()
				}
			else if (e.type == Event.REMOVED_FROM_STAGE)
			{
				offEnable()
				}
			}
		/**
		 * 启用 
		 * @return 
		 * 
		 */			
		public  function onEnable():void{ }
		/**
		 * 禁用 
		 * @return 
		 * 
		 */		
		public  function offEnable():void{}

		/**
		 * 获取对象实例的根容器IDataView对象实例路径
		 * @param obj 可视化对象
		 * @return 
		 * 
		 */		
		public function getRoot(obj:DisplayObject):String{
			    
			var treePath:String = ""   
				
			function getTreePath(obj:DisplayObject):String{
			    
				treePath == ""?treePath = obj.name:treePath = obj.name + "." + treePath
				if (obj.parent == null) { return treePath; }
				if (obj.parent is DisplayObject==false) {
					return treePath;
				}
				return getTreePath(obj.parent)
			}
			
			return getTreePath(obj) 
	    }
	    

    }
}